#ifndef CLIENT_H
#define CLIENT_H

#include <QMainWindow>
#include <QHBoxLayout>
#include <QListWidget>
#include <QLineEdit>
#include <QSplitter>
#include <QPushButton>
#include <QStackedWidget>
#include <QLabel>
#include <QPropertyAnimation>
#include <QMouseEvent>
#include <QSqlQuery>
#include "settingsmenu.h"
#include <thread>
#include <QSocketNotifier>


class Client : public QMainWindow
{
    Q_OBJECT

public:
    Client(QWidget *parent = nullptr);
    ~Client();

public slots:
    void updateChatList();

private:

    QSocketNotifier* notifier;

    QSplitter* splitterBetweenListDisplay; // general
    QWidget* leftWidget;
    QWidget* rightWidget;

    QLabel* stackRightPartLabel;
    QStackedWidget* stackMain;

    QHBoxLayout* upperChatsHLayout;
    QPushButton* settingMenuButton;
    QHBoxLayout* createChatHLayout;
    QPushButton* createChatButton;
    QVBoxLayout* chatsVLayout;
    QListWidget* chatsList;         // the left side of the client
    QLineEdit* searchChat;

    QHBoxLayout* upperChatMsgHLayout;
    QLabel* upperLabel;             // the right side of the client
    QVBoxLayout* msgVLayout;
    QListWidget* msgList;
    QHBoxLayout* lowerChatHLayout;
    QLineEdit* msgEdit;
    QPushButton* msgSendButton;

    settingsMenu* settingMenu;
    QPropertyAnimation *animation;
    QWidget* overlay;
    bool animationRunning;


    void build();

    void connecting();
    void renderingChats();
    void showOverlay();
    void processServerMessages();

signals:
    void updateChatListSignal();

public:
    void hideOverlay();

protected:
    void resizeEvent(QResizeEvent *event) override;
    void mousePressEvent(QMouseEvent* event) override;
};
#endif // CLIENT_H
